/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Aug 29, 2013  4:56:55 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : com.tis.interfaces.servlet
 * File Name : UserSecurityInformation.java
 * TODO
 */
package com.tis.interfaces.servlet;

import javax.servlet.jsp.tagext.SimpleTagSupport;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.JspFragment;

import promis.utility.CommonService;

import com.tis.database.entitys.security.AdUserLogin;
import com.tis.interfaces.apps.SESSION_MANAGE;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Aug 29, 2013 : 4:56:55 PM 
 * CreateBy=Chatree Siangklom
 * TODO User this tag After login ref to session variable name = [SESSION_MANAGE.SECURITY_PAGE.AdUserLogin] 
 */
public class UserSecurityInformation extends SimpleTagSupport {
	private static final long serialVersionUID = 1L;
	
	private String prefix = "";
	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}

	/** (Javadoc)
	 * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
	 * Date =Aug 29, 2013 : 5:01:13 PM 
	 * CreateBy=Chatree Siangklom
	 * TODO
	 */
	@Override
	public void doTag() throws JspException, IOException {	
		super.doTag();
		
		JspWriter out = getJspContext().getOut();
		try{
			
			JspFragment f = getJspBody();
			if(f != null) f.invoke(out);
			
			PageContext pageContext = (PageContext) getJspContext();  
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			
			HttpSession session = request.getSession();		 	
			Object objSession = session.getAttribute(SESSION_MANAGE.SECURITY_PAGE.AdUserLogin);
			String fullname = "";
					
				if(!CommonService.IsNull(objSession)){
					AdUserLogin adUserLoin = (AdUserLogin)objSession;
					fullname = CommonService.IsNullRString(adUserLoin.getTitleName()) + CommonService.IsNullRString(adUserLoin.getFirstName()) + " " + CommonService.IsNullRString(adUserLoin.getLastName());
				}else{
					fullname = "Unknow.";
				}
			out.print(CommonService.IsNullRString(prefix) + fullname);
			
		}catch(IOException ex){
			throw new JspException("Error in UserSecurityInformation tag", ex);
		}
	}
}
